<?php
Yii::import('zii.widgets.CListView');
class CAuctionsPool extends CListView{
	public $itemsCssClass='auction-pool';
	public $template='{items}{pager}';
	public $autoHeight;
	
	protected $autoHeightValue;
	public function init(){
		$this->itemView =(empty($this->itemView))? 'application.components.widgets._CAuctionsItem':$this->itemView;
		$this->itemsTagName = 'ul';
		$this->pager=array(
			'class' => 'application.components.widgets.pagers.AuctionPoolPager',
			'header'=>'',
			'prevPageLabel'=>"<",
			'nextPageLabel'=>'>',
			'maxButtonCount'=>10,
			'previousPageCssClass'=>'prev',
			'nextPageCssClass'=>'next',
		);
		$this->pagerCssClass .= ' auction-pool-page';
		
		if (!empty($this->autoHeight)) {
			$this->autoHeightValue = 'height:'.(ceil($this->dataProvider->getPagination()->getLimit()/2) * $this->autoHeight['itemHeight'] ) . 'px';
		}
		
		parent::init();
	}
	
	public function renderItems()
	{
		$htmlOptions = array(
			'class' => $this->itemsCssClass,
			'style' => $this->autoHeightValue
		);
		echo CHtml::openTag($this->itemsTagName,$htmlOptions)."\n";
		$data=$this->dataProvider->getData();
		if(($n=count($data))>0)
		{
			$owner=$this->getOwner();
			$viewFile=$owner->getViewFile($this->itemView);
			$j=0;
			foreach($data as $i=>$item)
			{
				$data=$this->viewData;
				$data['index']=$i;
				$data['data']=$item;
				$data['widget']=$this;
				$owner->renderFile($viewFile,$data);
				if($j++ < $n-1)
					echo $this->separator;
			}
		}
		else
			$this->renderEmptyText();
		echo CHtml::closeTag($this->itemsTagName);
	}
}